import { _decorator, Component, Node, Label, find } from 'cc';
const { ccclass, property } = _decorator;

import ChengYu_GameFunctions from "../Common/ChengYu_GameFunctions";
import ChengYu_CommonFunction from "../Utils/ChengYu_CommonFunction";


@ccclass('ChengYuIdiomInfoPanel')
export default class ChengYu_IdiomInfoPanel extends Component {
    public static Instance: ChengYu_IdiomInfoPanel;
    @property(Node)
    Button_close: Node | null = null;
    //    // @property(Node)
    //    // Button_ok: Node = null;
    @property(Node)
    Node_idiom: Node | null = null;
    @property(Label)
    Label_exp: Label | null = null;
    @property(Label)
    Label_outplace: Label | null = null;
    @property(Label)
    Label_outplace_title: Label | null = null;
    private mainNode: Node | null = null;
    chengyu: string;
    data: any;
    onLoad() {
        ChengYu_IdiomInfoPanel.Instance = this;

        this.node.active = false;

        // super.onLoad();

        this.Button_close.on(Node.EventType.TOUCH_END, this.On_Button_close, this);
    }
    On_Button_close() {
        this.node.active = false;
    }
    async ShowOn(params?: any) {
        this.node.active = true;

        this.chengyu = params;
        this.data = await ChengYu_GameFunctions.GetChengYuData(this.chengyu);

        this.Init();
    }
    protected initUI(): void {
        // this.registClickEvent(this.Button_ok, this.On_Button_ok);

        // this.mainNode = this.findNode("Node_main");
    }
    async on_show(params?: any) {
        this.chengyu = params;
        this.data = await ChengYu_GameFunctions.GetChengYuData(this.chengyu);

        this.Init();
    }
    Init() {
        const pinyin = this.data.pinyin.split(" ");
        const exp = this.data.exp;
        const outplace = this.data.outplace;

        // console.log(`pinyin`, pinyin);
        // console.log(`exp`, exp);
        // console.log(`outplace`, outplace);

        ChengYu_CommonFunction.SetAllChildrenAtive(this.Node_idiom, false);
        const count: number = this.chengyu.length;
        for (let index = 0; index <= count - 1; index++) {
            let Node_chengyu = ChengYu_CommonFunction.GetFreeChild(this.Node_idiom);
            Node_chengyu.active = true;

            ChengYu_CommonFunction.SetAllChildrenAtive(Node_chengyu, false);
            const chengyu = this.chengyu[index];
            const word_pinyin = pinyin[index];

            // console.log(`成语`, chengyu);

            // // 字
            const Label_word: Label = find("Label_word", Node_chengyu).getComponent(Label);
            Label_word.node.active = true;
            Label_word.string = chengyu;
            const Label_pinyin: Label = find("Label_pinyin", Node_chengyu).getComponent(Label);
            Label_pinyin.node.active = true;
            Label_pinyin.string = word_pinyin;
        }

        this.Label_exp.string = exp;
        if (outplace == null) {
            this.Label_outplace_title.node.active = false;
            this.Label_outplace.node.active = false;
            this.Label_outplace.string = "无";
        } else {
            this.Label_outplace_title.node.active = true;
            this.Label_outplace.node.active = true;
            this.Label_outplace.string = outplace;
        }
    }
    On_Button_ok() {
        // this.hide();
        // this.share();
    }
    //    // share() {
    //    //     let params = {
    //    //         offY: 140,
    //    //     };
    //    //     ShareImageMgr.shareImageChengyuTip(this.mainNode, params);
    //    // }
    //    // protected on_hide() { }
}